<?php
namespace Cyfy;

/**
 * Start file
 */

ini_set("display_errors", "On");
ini_set("error_reporting", E_ALL & ~E_NOTICE);


if(file_exists("cfg/cyfy.php") == false){
    die("cyfy is not installed. Follow the instructions in README.txt.");
}

include_once('Cyfy/Log.php');

// error handler
set_error_handler(array("\Cyfy\Log", "errorHandler"));

// log start
\Cyfy\Log :: start(true);

// Including the files
include_once('functions.php'); //autoloading
include_once('cfg/cyfy.php');
include_once('dibi-1.2/dibi.minified/dibi.min.php');



// DIBI CONNECT
\dibi::connect(array(
    'driver'   => \Cyfy\Cyfy ::  $dbDriver,
    'host'     => \Cyfy\Cyfy ::  $dbHost,
    'username' => \Cyfy\Cyfy ::  $dbUsername,
    'password' => \Cyfy\Cyfy ::  $dbPassword,
    'database' => \Cyfy\Cyfy ::  $dbDatabase,
    'charset'  => 'utf8',
));

// DIBI TABLE PREFIX
\dibi::addSubst('cyfy', \Cyfy\Cyfy ::  $dbPrefix);

// Starting session
session_start();

// utf
Header("Content-Type: text/html;charset=UTF-8");

// Crops the URL, if contains / at the end
\Cyfy\Cyfy ::  $query = $_GET["q"];
if(preg_match("/\/$/",\Cyfy\Cyfy ::  $query))
{
	\Cyfy\Cyfy ::  $query = substr(\Cyfy\Cyfy ::  $query, 0, -1);
}

// Initializing modules
\Cyfy\Modules :: prepare();

\Cyfy\Log :: write("Modules prepared.");

// load languages
\Cyfy\Language :: load();

\Cyfy\Log :: write("Language loaded.");

// loading language constants
\Cyfy\Constants :: load();

// loads custom settings, if exists
if(file_exists(\Cyfy\Cyfy ::  $configDir . "custom.php"))
{
    include_once(\Cyfy\Cyfy ::  $configDir . "custom.php");
}

// if no query - index
if(\Cyfy\Cyfy ::  $query == "")
{
    \Cyfy\Cyfy ::  $query = "index";
}

// Loads starters
\Cyfy\Modules :: loadStarters();
\Cyfy\Log :: write("Starters loaded.");


